package com.jiandaoshou.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.jiandaoshou.entry.ShopInfo;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2016/12/11.
 */

public class UserUtils {


    public static final SharedPreferences getUserShare(Context ctx) {
        return ctx.getSharedPreferences("userinfo", 0);
    }

    public static final void saveUser(Context ctx, ShopInfo info) {
        getUserShare(ctx).edit().putString("userid", info.getStrID()).putString("strShopName", info.getStrShopName()).putString("strShopPhone",info.getStrLXRPhone()).commit();
    }

    public static final String getUserid(Context ctx){
        return getUserShare(ctx).getString("userid", "");
    }

    public static final String getShopPhone(Context ctx){
        return getUserShare(ctx).getString("strShopPhone", "");
    }

    public static final boolean checkIsLogin(Context ctx){
        return getUserid(ctx).equals("") == false;
    }

    public static final void loginOut(Context ctx){
        JPushInterface.setAlias(ctx,"",null);
        getUserShare(ctx).edit().clear().commit();
    }

    public static final void saveBalance(Context ctx, float balance){
        getUserShare(ctx).edit().putFloat("balance", balance).commit();
    }
    public static final float getBalance(Context ctx){
        float jine=getUserShare(ctx).getFloat("balance", 0);

        return Float.parseFloat(CommonUtil.roundDouble(jine));
    }

    public static final SharedPreferences getOtherInfo(Context ctx) {
        return ctx.getSharedPreferences("other_info", 0);
    }

    public static final void saveIsTishiYin(Context ctx, boolean b) {
        getOtherInfo(ctx).edit().putBoolean("tishiyin", b).commit();
    }

    public static final boolean getIsTiShiYin(Context ctx){
        return getOtherInfo(ctx).getBoolean("tishiyin", true);
    }


}
